﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Provenance.ErrorCount;
using Provenance.Write.Api.Application.Command.User;

namespace Provenance.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IMediator _mediator;
        public UserController(IMediator mediator)
        {
            _mediator = mediator;
        }
        #region 权限相关
        [HttpPost]
        public async Task<ApiResult> InsertPermission(InsertPermissionCommand param)
        {
            return await _mediator.Send(param);
        }
        [HttpDelete]
        public async Task<ApiResult> DeletePermission(int id)
        {
            return await _mediator.Send(new DeletePermissionCommand()
            {
                PermissionId=id
            });
        }
        [HttpPut]
        public async Task<ApiResult> UpdatePermission(UpdatePermissionCommand param)
        {
            return await _mediator.Send(param);
        }
        #endregion

        #region 角色相关
        [HttpPost]
        public async Task<ApiResult> InsertRole(InsertRoleCommand param)
        {
            return await _mediator.Send(param);
        }
        [HttpDelete]
        public async Task<ApiResult> DeleteRole(int id)
        {
            return await _mediator.Send(new DeleteRoleCommand()
            {
                RoleId=id
            });
        }
        [HttpPut]
        public async Task<ApiResult> UpdateRole(UpdateRoleCommand param)
        {
            return await _mediator.Send(param);
        }
        #endregion

        #region 用户相关
        [HttpPost]
        public async Task<ApiResult> InsertUser(InsertUserCommand param)
        {
            return await _mediator.Send(param);
        }
        [HttpDelete]
        public async Task<ApiResult> DeleteUser(int id)
        {
            return await _mediator.Send(new DeleteUserCommand()
            {
                UserId=id
            });
        }
        [HttpPut]
        public async Task<ApiResult> UpdateUser(UpdateUserCommand param)
        {
            return await _mediator.Send(param);
        }
        #endregion



    }
}
